package com.yjt.javatest.handler;

import com.yjt.javatest.utils.APIResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice(basePackages = {"com.example.javatest.controller"})
public class GlobalExceptionHandler {
    @ExceptionHandler(RuntimeException.class)
    public APIResponse runtimeError(RuntimeException e) {
        log.warn("发生错误：",e);
        e.printStackTrace();
        return APIResponse.error(e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    public APIResponse unknownError(Exception e) {
        log.warn("发生错误：",e);
        e.printStackTrace();
        return APIResponse.error("发生未知错误，请反馈");
    }
}
